import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { BoardVo } from 'src/app/model/board-vo';
import { BoardService } from 'src/app/services/board.service';
import { environment } from 'src/environments/environment';
@Component({
  selector: 'app-member-favorite-board-embed',
  templateUrl: './member-favorite-board-embed.component.html',
  styles: [``]
})
export class MemberFavoriteBoardEmbedComponent implements OnInit, OnChanges {
  @Input('uid')
  public uid!: number;
  public favoriteBoard: BoardVo[] = [];

  constructor(private boardService: BoardService) { }

  ngOnInit(): void {
    this.getFavoriteBoardDate();
  }

  ngOnChanges(changes: SimpleChanges): void {
    if(changes['uid'].firstChange){
      console.log('[MemberFavoriteBoard-Emd]is first');
      return;
    }
    console.log('[MemberFavoriteBoard-Emd]is not first');
    if(changes['uid'].previousValue != changes['uid'].currentValue){
      this.uid = changes['uid'].currentValue;
      this.getFavoriteBoardDate();
    }
  }

  private getFavoriteBoardDate(): void{
    this.boardService.getMemberStar(this.uid ?? 0, environment.indexSize, "auto").subscribe(res=>this.favoriteBoard = res);
  }
}
